class tuozhuai {
  constructor() {
    this.div = document.getElementsByClassName("div1")[0];
    this.div1 = document.getElementsByClassName("div2")[0];


  }
  show(){
      var div = this.div1;
      var div1 = this.div;
      var x=0;
      var y=0;
      div.onmousedown = function(ev){
        //  alert(11)
        div.style.left=x+'px';
        div.style.top=y+'px';
         var ev = ev||event;
          var disX = ev.offsetX;
          var disY = ev.offsetY;
         document.onmousemove = function(ev){
           var ev = ev||event;
             x = ev.clientX-disX;
             y = ev.clientY-disY;
           div.style.left = x+"px";
           div.style.top = y+"px";
         }
         document.onmouseup = function(){
           document.onmousemove = null;
           document.onmouseup=null;
            div1.style.left=x+'px';
            div1.style.top=y+'px';
         }
         return false;
      }

  }
}
let str = new tuozhuai();
str.show();
